package ${packageName};

/**
 * 类${className}BeanUtil.java的实现描述：
 * Copyright (c) 2016, brcikworker All Rights Reserved.
 * @Author ${author}
 * @Date ${createTime}
 */
/**
 * @apiDefine ${className} 模块(${className})
 */


@RestController
@RequestMapping(value = "/${className}",  produces = "application/json")
public class ${className}Controller {
	
	@Autowired
	private ${className}Service ${classNameFirstLowcase}Service;
	
	/**
	 *  @api {POST} http://121.196.232.233/card/${className}/create?token={token} 1-
	 *  @apiName create
	 *  @apiGroup ${className}
	 *  @apiParamExample {json} Request-Example: 
	 *  {
	 *  }
	 *  @apiSuccessExample {json} Success-Response: HTTP/1.1  CREATED 
	 *  {
	 *  "code":"201",
	 *  "message":"创建成功"
	 *  }
	 */

	@ResponseStatus(value = HttpStatus.CREATED)
	@RequestMapping(value = "create", method = RequestMethod.POST)
	public String create(HttpServletRequest request, @RequestBody ${className} ${classNameFirstLowcase}){
		return JSON.toJSONString(this.${classNameFirstLowcase}Service.save(${classNameFirstLowcase}));
	}
	
	/**
	 *  @api {GET} http://121.196.232.233/card/${classNameFirstLowcase}/{id}? 2-
	 *  @apiName findOne
	 *  @apiGroup ${className}
	 *  @apiSuccessExample {json} Success-Response: HTTP/1.1  CREATED 
	 *		{
	 *		}
	 */
	@RequestMapping(value = "{id}", method = RequestMethod.GET)
	public String getOne(@PathVariable("id") Long id){
		return JSON.toJSONString(this.${classNameFirstLowcase}Service.findOne(id));
	}
	
	
	/**
	 *  @api {PUT} http://121.196.232.233/card/${classNameFirstLowcase}/update?token={token} 3-
	 *  @apiName update
	 *  @apiGroup ${className}
	 *  @apiParamExample {json} Request-Example: 
	 *  {
	 *  	"id":1  //标记字段必须上送
	 *  }
	 *  @apiSuccessExample {json} Success-Response: HTTP/1.1  CREATED 
     *     {
     *       "code": "202",
     *       "message": "更新成功"
     *     }
	 */
	@RequestMapping(value = "update", method = RequestMethod.PUT)
	public String update(@RequestBody ${className} ${classNameFirstLowcase}Model){
		return JSON.toJSONString(this.${classNameFirstLowcase}Service.updateById(${classNameFirstLowcase}));
	}
	
	/**
	 *  @api {DELETE} http://121.196.232.233/card/${classNameFirstLowcase}/{id}? 4-
	 *  @apiName delete
	 *  @apiGroup ${className}
	 *  @apiSuccessExample {json} Success-Response: HTTP/1.1  CREATED 
	 *  {
	 *  "code":"203",
	 *  "message":"删除成功"
	 *  }
	 */
	@RequestMapping(value = "{id}", method = RequestMethod.DELETE)
	public String delete(@PathVariable("id") Long id){
		return JSON.toJSONString(this.${classNameFirstLowcase}Service.delete(id));
	}
	
	/**
	 *  @api {GET} http://121.196.232.233/card/${classNameFirstLowcase}?currentPage={currentPage}&size={size} 5-
	 *  @apiName findPage
	 *  @apiGroup ${className}
	 *  @apiSuccessExample {json} Success-Response: HTTP/1.1  CREATED 
     *        {
     *        }
	 */
	@RequestMapping(method = RequestMethod.GET)
	public String getPage(@RequestParam("currentPage") Integer currentPage, @RequestParam("size") Integer size){
		return JSON.toJSONString(this.${classNameFirstLowcase}Service.selectPage(currentPage, size));
	}
}
